package com.sskj.mine.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.mine.bean.ImgUrlBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.CertificationActivity;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;

import java.io.File;


public class CertificationActivityPresenter extends BasePresenter<CertificationActivity> {


    /**
     * 上传图片
     *
     * @param file 文件
     * @return
     */
    public void uploadImg(File file) {
        httpService.uploadImg(file)
                .execute(new JsonCallBack<HttpData<ImgUrlBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<ImgUrlBean>> response) {
                        HttpData<ImgUrlBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updatePath(httpData.getData().getUrl());
                        }
                    }
                });
    }

    /**
     * 实名认证
     *
     * @param username       用户名
     * @param idCardNo       身份证号
     * @param idCardFrontImg 前身份证
     * @param idCardBackImg  后身份证
     * @param selfieImg      手持
     * @return
     */
    public void verify(String username, String idCardNo, String idCardFrontImg, String idCardBackImg, String selfieImg,String type,String account) {
        httpService.verify(username, idCardNo, idCardFrontImg, idCardBackImg, selfieImg,type,account)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.onSubmitVerifyResponseSuccess();
                        }
                    }
                });
    }

    /**
     * 实名认证
     *
     * @param cardNum  证件号
     * @param realName 真实姓名
     * @param type     认证类型 1 身份证 2 护照
     * @param cardimg1 身份证正面/护照
     * @param cardimg2 身份证反面
     * @param cardimg3 手持身份证
     * @return
     */
    public void realNameVerify(String cardNum, String realName, int type, String cardimg1, String cardimg2, String cardimg3) {
        httpService.realNameVerify(cardNum, realName, type, cardimg1, cardimg2, cardimg3)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.onSubmitVerifyResponseSuccess();
                        }
                    }
                });
    }
}
